package edu.towson.cosc603.coffeemaker;

import junit.framework.TestCase;

public class CoffeeMakerTest extends TestCase {

		private CoffeeMaker cm;
		private Inventory i;
		private Recipe r1;

		public void setUp() {
			cm = new CoffeeMaker();
			i = cm.checkInventory();

			r1 = new Recipe();
			r1.setName("Coffee");
			r1.setPrice(50);
			r1.setAmtCoffee(6);
			r1.setAmtMilk(1);
			r1.setAmtSugar(1);
			r1.setAmtChocolate(0);
		}

		public void testAddRecipe1() {
			assertTrue(cm.addRecipe(r1));
		}
		public void testAddRecipe2() {
			assertTrue(cm.addRecipe(r1));
			assertFalse(cm.addRecipe(r1));
		}
		public void testAddRecipe3() {
			Recipe r2 = new Recipe(), r3 = new Recipe(), r4 = new Recipe(), r5 = new Recipe();
			assertTrue(cm.addRecipe(r1));
			r2.setPrice(50);
			r2.setAmtCoffee(6);
			r2.setAmtMilk(1);
			r2.setAmtSugar(1);
			r2.setAmtChocolate(0);
			r2.setName("1");
			assertTrue(cm.addRecipe(r2));
			r3.setPrice(50);
			r3.setAmtCoffee(6);
			r3.setAmtMilk(1);
			r3.setAmtSugar(1);
			r3.setAmtChocolate(0);
			r3.setName("3");
			assertTrue(cm.addRecipe(r3));
			r4.setPrice(50);
			r4.setAmtCoffee(6);
			r4.setAmtMilk(1);
			r4.setAmtSugar(1);
			r4.setAmtChocolate(0);
			r4.setName("7");
			assertTrue(cm.addRecipe(r4));
			r5.setPrice(50);
			r5.setAmtCoffee(6);
			r5.setAmtMilk(1);
			r5.setAmtSugar(1);
			r5.setAmtChocolate(0);
			r5.setName("13");
			assertFalse(cm.addRecipe(r5));
		}

		public void testDeleteRecipe1() {
			cm.addRecipe(r1);
			assertTrue(cm.deleteRecipe(r1));
		}

		public void testEditRecipe1() {
			cm.addRecipe(r1);
			Recipe newRecipe = new Recipe();
			newRecipe = r1;
			newRecipe.setAmtSugar(2);
			assertTrue(cm.editRecipe(r1, newRecipe));
		}
		public void testEditRecipe2() {
			cm.addRecipe(r1);
			Recipe r2 = new Recipe(), r3 = new Recipe(), r4 = new Recipe(), r5 = new Recipe();
			r2.setPrice(50);
			r2.setAmtCoffee(6);
			r2.setAmtMilk(1);
			r2.setAmtSugar(1);
			r2.setAmtChocolate(0);
			r2.setName("1");
			assertTrue(cm.addRecipe(r2));
			r3.setPrice(50);
			r3.setAmtCoffee(6);
			r3.setAmtMilk(1);
			r3.setAmtSugar(1);
			r3.setAmtChocolate(0);
			r3.setName("3");
			assertTrue(cm.addRecipe(r3));
			r4.setPrice(50);
			r4.setAmtCoffee(6);
			r4.setAmtMilk(1);
			r4.setAmtSugar(1);
			r4.setAmtChocolate(0);
			r4.setName("7");
			assertTrue(cm.addRecipe(r4));
			r5.setPrice(50);
			r5.setAmtCoffee(6);
			r5.setAmtMilk(1);
			r5.setAmtSugar(1);
			r5.setAmtChocolate(0);
			r5.setName("13");
			assertFalse(cm.editRecipe(r4, r5));
			Recipe newRecipe = r1;
			newRecipe.setAmtSugar(2);
			assertFalse(cm.editRecipe(r1, newRecipe));
			newRecipe.setAmtSugar(5);
			assertFalse(cm.editRecipe(r1, newRecipe));
			newRecipe.setAmtSugar(2);
			assertFalse(cm.editRecipe(newRecipe, newRecipe));
			
		}
	
	public void testCoffeeMaker() {
		CoffeeMaker newCM = new CoffeeMaker();
		assertNotNull(newCM);
	}

	public void testAddInventory() {
		assertTrue(cm.addInventory(2, 1, 1, 1));
		Inventory inv = cm.checkInventory();
		assertEquals(inv.getChocolate(),16);
		assertEquals(inv.getCoffee(),17);
		assertEquals(inv.getMilk(),16);
		assertEquals(inv.getSugar(),16);
		assertFalse(cm.addInventory(-2, -1, -1, -1));
	}
	public void testAddInventoryInvalid() {
		assertFalse(cm.addInventory(-2, -1, -1, -1));
	}
	public void testCheckInventory() {
		assertTrue(cm.addInventory(1, 1, 1, 1));
		Inventory inv = cm.checkInventory();
		assertNotNull(inv);
		assertEquals(inv.getCoffee(),16);
		assertEquals(inv.getChocolate(),16);
		assertEquals(inv.getMilk(),16);
		assertEquals(inv.getSugar(),16);
	}

	public void testMakeCoffee() {
		assertTrue(cm.addRecipe(r1));
		assertEquals(cm.makeCoffee(r1, 50),0);
	}
	public void testMakeCoffeeInvalidPrice() {
		assertTrue(cm.addRecipe(r1));
		assertEquals(cm.makeCoffee(r1, 10),10);
	}
	public void testMakeCoffeeInvalidIngredients() {
		assertTrue(cm.addRecipe(r1));
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),0);
		assertEquals(cm.makeCoffee(r1, 50),50);
	}

	public void testGetRecipes() {
		assertTrue(cm.addRecipe(r1));
		Recipe r2 = new Recipe();
		r2.setName("Mocha");
		r2.setPrice(50);
		r2.setAmtCoffee(6);
		r2.setAmtMilk(3);
		r2.setAmtSugar(0);
		r2.setAmtChocolate(2);
		assertTrue(cm.addRecipe(r2));
		Recipe[] rmArr = cm.getRecipes();
		assertEquals(rmArr.length,4);
		Recipe rmTest = rmArr[2];
		assertNotNull(rmTest);
		assertEquals(rmTest.getPrice(),50);
	}

	public void testGetRecipeForName() {
		assertTrue(cm.addRecipe(r1));
		Recipe r2 = new Recipe();
		r2.setName("Mocha");
		r2.setPrice(50);
		r2.setAmtCoffee(6);
		r2.setAmtMilk(3);
		r2.setAmtSugar(0);
		r2.setAmtChocolate(2);
		assertTrue(cm.addRecipe(r2));
		Recipe rm = cm.getRecipeForName("Mocha");
		assertEquals(rm.getName(),"Mocha");
	}

}
